package edu.inf3.j2ee.entities;

import java.util.Vector;

public class Group {
	private long id;
	private String name;
	private Vector<Permission> permissions;
	
	public Group(){
		this.permissions = new Vector<Permission>();
	}
	
	public Group(String name){
		this.permissions = new Vector<Permission>();
		this.setName(name);
	}

	/**
	 * @return the id
	 */
	public long getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(long id) {
		this.id = id;
	}
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	public boolean permit (String perm, String target){
		
		for (Permission p:this.permissions){
			if (p.getTarget() == target){
				if (p.can(perm))
					return false;
			}
		}
		
		return true;
	}
	
	public boolean addPermission (String perm, String target){
		if (!this.permit(perm, target)){
			this.permissions.add(new Permission(perm, target));
			return true;
		}
		return false;
	}	
}

